package panels.util;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;

import javax.swing.JPanel;

public class JLinePanel extends JPanel {

	/**
	 * A simple panel that draws a line from the center of the panel to
	 * the outer edged. Mainly used in combination with the border layout to draw frames
	 */
	private static final long serialVersionUID = 1L;
	private boolean	drawNorth;
	private boolean	drawEast;
	private boolean	drawSouth;
	private boolean drawWest;
	
	private Color	lineColor;
	private Stroke	lineStroke;
	
	
	public JLinePanel() {
		init(true,true,true,true);
	}
	
	public void init(boolean N, boolean E, boolean S, boolean W) {
		setDrawNorth(N);
		setDrawEast(E);
		setDrawSouth(S);
		setDrawWest(W);
	}

	public boolean isDrawNorth() {
		return drawNorth;
	}

	public void setDrawNorth(boolean drawNorth) {
		this.drawNorth = drawNorth;
	}

	public boolean isDrawEast() {
		return drawEast;
	}

	public void setDrawEast(boolean drawEast) {
		this.drawEast = drawEast;
	}

	public boolean isDrawSouth() {
		return drawSouth;
	}

	public void setDrawSouth(boolean drawSouth) {
		this.drawSouth = drawSouth;
	}

	public boolean isDrawWest() {
		return drawWest;
	}

	public void setDrawWest(boolean drawWest) {
		this.drawWest = drawWest;
	}
	
	@Override
	public void paint(Graphics G) {
		Graphics2D 	g2d			= (Graphics2D) G;
		Color		oldColor	= g2d.getColor();
		Stroke		oldStroke	= g2d.getStroke();

		g2d.setColor(getLineColor());
		g2d.setStroke(getLineStroke());
		
		if (isDrawNorth())	g2d.drawLine(getWidth()/2, getHeight()/2, getWidth()/2,	0);
		if (isDrawEast())	g2d.drawLine(getWidth()/2, getHeight()/2, getWidth(),	getHeight()/2);
		if (isDrawSouth())	g2d.drawLine(getWidth()/2, getHeight()/2, getWidth()/2,	getHeight());
		if (isDrawWest())	g2d.drawLine(getWidth()/2, getHeight()/2, 0,			getHeight()/2);
		
		g2d.setColor(oldColor);
		g2d.setStroke(oldStroke);
	}

	public Color getLineColor() {
		return lineColor;
	}

	public void setLineColor(Color lineColor) {
		this.lineColor = lineColor;
	}

	public Stroke getLineStroke() {
		return lineStroke;
	}

	public void setLineStroke(Stroke lineStroke) {
		this.lineStroke = lineStroke;
	}
}